package queue;

public class MyQueue {


    static class Node {
        public int val;
        public Node next;
        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;
    public Node tail;

    //入队
    public void offer(int val) {
        Node node = new Node(val);
        if(head == null) {
            head = node;
            tail = node;
        } else {
            tail.next = node;
            tail = tail.next;
        }

    }

    //出队
    public int poll() {
        if(head == null) {
            return -1;
        }
        int oldVal = head.val;
        if(head.next == null) {
            head = tail = null;
        } else {
            head = head.next;
        }
        return oldVal;
    }

    //查看队头元素
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.val;
    }

}
